<!-- 用户 》 基础 -->

<template>
  <div class="row9">
    <EasyRow col2>
      <FormInput label="登录账号" bind="account" :max="20" required />

      <FormPhone label="手机号" :disabled="isEdit && !CORE.MAP.USER_MOBILE_EDIT" required />
    </EasyRow>

    <EasyRow col2>
      <FormPassword
        label="登录密码"
        bind="pwd"
        :tip="isAdd ? '请输入登录密码' : '输入新密码进行重置'"
        v-bind="CORE.MAP.USER_PASSWORD"
        :required="isAdd"
      />
      <FormPassword label="确认密码" bind="repeatPwd" same="pwd" :max="20" :required="isAdd" />
    </EasyRow>

    <EasyRow col2>
      <FormInput label="用户姓名" bind="name" :max="20" required />
      <FormSelect label="用户性别" bind="gender" :dict="CORE.DICT.GENDER" noClear />
    </EasyRow>

    <EasyRow col2>
      <FormSelectMulti label="岗位" bind="jobTypeId, jobTypeValue" :dict="CORE.DICT.job_desc" join required />
      <FormNum
        v-if="CORE.MAP.USER_HAS_SORT"
        label="用户排序"
        bind="sort"
        :min="1"
        :max="isAdd ? total + 1 : total"
        initMax
        noTip
        third
      />
    </EasyRow>

    <EasyRow col2>
      <FormStatus label="账号状态" isRadio />
    </EasyRow>

    <EasyRow col2>
      <FormRadio label="有效期" bind="validDate" :dict="DICT.VALID_DATE" @change="changeDate" />
      <FormDate
        v-if="one.validDate === 2"
        label="有效期至"
        bind="someDate"
        tip="请选择有效期"
        lastSecond
        required
        @change="changeDate"
      />
    </EasyRow>

    <EasyRow col2>
      <FormRadio label="有效次数" bind="validNum" :dict="DICT.VALID_NUM" @change="changeNum" />
      <FormNum v-if="one.validNum === 2" label="剩余次数" bind="someNum" :min="0" required @change="changeNum" />
    </EasyRow>

    <FormTextarea label="用户描述" bind="describe" :rows="3" :max="20" />
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'UserBasic',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb()],

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 切换有效期
     */
    changeDate() {
      this.one.expireTime = this.one.validDate === 1 ? -1 : this.one.someDate
    },

    /**
     * 切换登录次数
     */
    changeNum() {
      this.one.loginLimit = this.one.validNum === 1 ? -1 : (this.one.someNum || -2)
    },
  },
}
</script>
